import matplotlib.pyplot as plt

# 设置字体和负号显示
plt.rcParams['font.sans-serif'] = ['SimHei']  # 使用黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

# 数据
years = list(range(2010, 2023))  # 年份列表
wheat = [385.495985, 386.909358, 393.834819, 394.19033, 395.216843,
        395.376923, 408.284707, 407.514989, 406.203, 425.51265,
        435.494972, 440.32005, 440.027904]
corn = [425.642048, 440.531489, 440.792286, 422.443783, 418.28237,
       423.727758, 429.482634, 443.900506, 441.96087, 439.849815,
       447.194819, 443.21483, 452.161301]
soybeans = [160.523555, 169.612097, 164.320786, 159.91325, 157.924923,
            169.388652, 179.569073, 179.252248, 188.252746, 190.25508,
            196.187378, 195.206221, 180.280762]
peanuts = [288.384787, 291.866527, 294.175014, 293.56671, 292.195358,
           289.17118, 289.574048, 294.858689, 294.196358, 284.980419,
           293.751469, 297.550701, 295.452319]

# 创建图表
plt.subplots()
plt.grid(color='white')  # 设置网格线颜色为白色

# 绘制每种作物的产量
plt.plot(years, wheat, marker='^', linestyle='-', color='black', label='Wheat')
plt.plot(years, corn, marker='s', linestyle='--', color='black', label='Corn')
plt.plot(years, soybeans, marker='D', linestyle='-.', color='black', label='Soybean')
plt.plot(years, peanuts, marker='o', linestyle=':', color='black', label='Peanut')

# 添加标题和标签
plt.xlabel('Year')
plt.ylabel('Yield (kg/mu)')

# 显示图例，并放在右上角
plt.legend(loc='upper right', bbox_to_anchor=(1, 0.8), borderpad=1)


# 显示网格
# plt.grid(True)
plt.savefig("产量.png", bbox_inches='tight', dpi=300)  # 设置 dpi 为 300，图片分辨率更高


# 显示图表
plt.show()
